import CountUI from "../../components/Count";
// import store from '../../redux/store'
// 引入connect用于连接UI与redux
import { connect } from 'react-redux';

import {
  createIncrementAction,
  createDecrementAction,
  createIncrementAsyncAction,
} from '../../redux/actions/count';

// 映射状态
// function mapStateToProps(state) {
//   return { count: state, }
// }
const mapStateToProps = (state) => ({ count: state });

// 映射操作状态的方法 
// function mapDispatchToProps(dispatch) {
//   return {
//     increment: (data) => {
//       dispatch(createIncrementAction(data));
//     },
//     decrement: (data) => {
//       dispatch(createDecrementAction(data));
//     },
//     asyncIncrement: (data, time) => {
//       dispatch(createIncrementAsyncAction(data, time));
//     }
//   }
// }

// mapDispatchToProps 可以接收两种参数
// 一种是接收普通函数
// 一种是接收一个action对象
// const mapDispatchToProps = (dispatch) => (
//   {
//     increment:(data) => dispatch(createIncrementAction(data)),
//     decrement:(data) => dispatch(createDecrementAction(data)),
//     asyncIncrement:(data,time) => dispatch(createIncrementAsyncAction(data,time)),
//   }
// )

const mapDispatchToProps = {
  increment: createIncrementAction,
  decrement: createDecrementAction,
  asyncIncrement: createIncrementAsyncAction,
}


export default connect(mapStateToProps, mapDispatchToProps)(CountUI);